package com.company.project.web;

import com.company.project.core.Result;
import com.company.project.core.ResultGenerator;
import com.company.project.model.VO.ProductVO;
import com.company.project.model.VO.TestVO;
import com.company.project.model.VO.ZzProductVO;
import com.company.project.model.VtColour;
import com.company.project.model.VtMachineNumber;
import com.company.project.model.VtMaterial;
import com.company.project.service.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class DictController {

    @Resource
    private VtColourService vtColourService;
    @Resource
    private VtMachineNumberService machineNumberService;

    @Resource
    private VtMaterialService vtMaterialService;

    @Resource
    private VtProductService vtProductService;
    @Resource
    private VtZzproductService  vtZzproductService;
    @GetMapping("/getAllDict")
    public Result getAllDict() {
        List<VtColour> colours = vtColourService.findAll();
        List<VtMachineNumber> machineNumbers = machineNumberService.findAll();
        List<VtMaterial> materials = vtMaterialService.findAll();
        List<ProductVO> productList = vtProductService.findProductMenu();
        List<ZzProductVO> zzProductVOList = vtZzproductService.findProductMenu();
        Map<String, Object> map = new HashMap<>();
        map.put("colour",colours);
        map.put("machineNumbers",machineNumbers);
        map.put("materials",materials);
        map.put("products",productList);
        map.put("zzProducts",zzProductVOList);
        return ResultGenerator.genSuccessResult(map);
    }

    @PostMapping("/test")
    public Result test(TestVO testVO) {
        System.out.println(testVO);
        return ResultGenerator.genSuccessResult(testVO);
    }

    @GetMapping("/testGet")
    public Result testGet(String query){
        System.out.println(query);
        return ResultGenerator.genSuccessResult(query);
    }
}
